﻿package com.jdplat.jdm.web.controller.system;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.jdplat.jdm.core.web.controller.BaseController;
import com.jdplat.jdm.web.entity.User;
import com.jdplat.jdm.web.service.system.ISystemUserService;

@Controller
@RequestMapping("/user")
public class SystemUserServiceController extends BaseController{
	protected Logger logger = LoggerFactory.getLogger(SystemUserServiceController.class);
	
	@Autowired
	public ISystemUserService systemUserService;
	
	@RequestMapping(value="/list",method={RequestMethod.GET})
	public ModelAndView getUserList(Model model){
    	model.addAttribute("data", systemUserService.selectUser());
        return new ModelAndView("user/user_list"); 
	}
	
	@RequestMapping(value = "toAdd" , method = RequestMethod.GET)
	public ModelAndView toAddComment() {
		return new ModelAndView("user/user_add");
	}
	
	@RequestMapping(value = "add" , method = RequestMethod.POST)
	public void addComment(User user) {
		user.setId(9);
		systemUserService.creatUser(user);
	}
	
	@RequiresPermissions("sys:user:delete")
	@RequestMapping(value = "delete/{id}" , method = { RequestMethod.POST, RequestMethod.GET }) 
	public String deleteUser(@PathVariable String id){
		systemUserService.delUser(id);
		return "redirect:/user/list";
	}
	
}
